package com.book.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author xuchangshuo
 * @date 2020/11/3 15:41
 */
@Configuration
public class MqConfig {

    //定义队列名称
    private static final String TEST_QUENE = "TEST_QUENE";

    //定义交换机
    private static final String TEST_EXCHANGE="test_exchange";


    //申明队列
    @Bean(TEST_QUENE)
    public Queue queue(){
        return new Queue(TEST_QUENE);
    }

    //申明交换机
    @Bean(TEST_EXCHANGE)
    public Exchange exchange(){
        return ExchangeBuilder.fanoutExchange(TEST_EXCHANGE).durable(true).build();
    }

    //绑定交换机和队列
    @Bean
    public Binding TEST_EXCHANGE_QUEUE(@Qualifier(TEST_QUENE) Queue queue , @Qualifier(TEST_EXCHANGE) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }
}
